package com.easylinkin.linkappapi.weather.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.easylinkin.linkappapi.weather.entity.WeatherRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * 天气记录Mapper接口
 */
@Mapper
public interface WeatherRecordMapper extends BaseMapper<WeatherRecord> {

    /**
     * 根据租户ID和时间范围查询天气记录
     * @param tenantId 租户ID
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 天气记录列表
     */
    @Select("SELECT * FROM app_weather_record WHERE tenant_id_ = #{tenantId} " +
            "AND create_time_ BETWEEN #{startTime} AND #{endTime} " +
            "ORDER BY create_time_ DESC")
    List<WeatherRecord> selectByTenantIdAndTimeRange(@Param("tenantId") String tenantId,
                                                      @Param("startTime") Date startTime,
                                                      @Param("endTime") Date endTime);

    /**
     * 根据租户ID查询最新的天气记录
     * @param tenantId 租户ID
     * @return 最新的天气记录
     */
    @Select("SELECT * FROM app_weather_record WHERE tenant_id_ = #{tenantId} " +
            "ORDER BY create_time_ DESC LIMIT 1")
    WeatherRecord selectLatestByTenantId(@Param("tenantId") String tenantId);

}